import request from './index'

// 获取首页数据
export const getGoodsDate = () => request({
    url: "/getGoodsDate",
    method: "get"
})


// 登陆请求
export const requestLogin = (phone, password) => request({
    url: "/login",
    method: "post",
    data: {
        phone,
        password
    }
})


// 注册请求
export const requestRegister = (username, phone, password) => request({
    url: '/register',
    method: "post",
    data: {
        username,
        phone,
        password
    }
})


// 添加到购物车
export const addGoods = item => request({
    url: "/addGoods",
    method: 'post',
    data: {
        item,
    }
})

// 删除购物车
export const reduceGoods = item => request({
    url: "/reduceGoods",
    method: "post",
    data: {
        item
    }
})

// 获取购物车商品
export const searchGoodsIntheCar = () => request({
    url: "/searchGoodsIntheCar",
    method: "get",
})

// 获取详情页数据
export const getGoodsDetails = _id => request({
    url: "/getGoodsDetails",
    method: 'get',
    params: {
        _id,
    }
})

// 获取地址列表数据
export const getLocationList = () => request({
    url: "/getLocationList",
    method: "get"
})

// 添加地址
export const addLocation = (name, phone, address, isDefaul) => request({
    url: "/addAddress",
    method: "post",
    data: {
        name,
        phone,
        address,
        isDefaul
    }
})

// 删除地址
export const delAddress = _id => request({
    url: '/delAddress',
    method: "post",
    data: {
        _id
    }
})


// 修改地址
export const updateAddress = (_id, name, phone, address, isDefaul) => request({
    url: '/updateAddress',
    method: "post",
    data: {
        _id,
        name,
        phone,
        address,
        isDefaul
    }
})


// 获取用户信息
export const getUserInfo = () => request({
    url: "/getUserInfo",
    method: 'get',
})


// 修改用户信息
export const updateUserInfo = (username, sex, birthday, age, introduce) => request({
    url: "/updateUserInfo",
    method: "post",
    data: {
        username,
        sex,
        birthday,
        age,
        introduce
    }
})


// 添加订单
export const addOrder = (sum,goods,address) => request({
    url:"/addOrder",
    method:'post',
    data:{
        sum,
        goods,
        address
    }
})

// 清空购物车
export const removeCar = () => request({
    url:"/removeCar",
    method:"post",
})

// 获取订单信息
export const getOrder = () => request({
    url:'/getOrder',
    method:"get"
})

// 获取单个订单
export const getOnesOrder = _id => request({
    url:"/getOnesOrder",
    method:'get',
    params:{
        _id,
    }
}) 


// 删除订单
export const delOrder = _id => request({
    url:'/delOrder',
    method:'post',
    data:{
        _id
    }
})


// 获取品牌商品信息
export const getBrandGoods = brand => request({
    url:"/getBrandGoods",
    method:"get",
    params:{
        brand
    }
})